/**
 * new MyPromise((resolve,reject) => {
 *      resolve()//
 * }).then((success) => {成功的状态},() => {失败的状态})
 * 
*/
class MyPromise{
    constructor(fun){
        this.status = 'pending';//进行中
        this.value = ''; //记录成功的值
        this.error = ''; //记录失败的信息

        //成功状态触发的函数
        let resolve = (success) => {
            this.status = 'fulfilled'; 
            this.value = success;
        }

        //失败状态触发的函数
        let reject = (error) => {
            this.status = 'rejected';
            this.error = error;
        }

        fun(resolve,reject)//执行
    }
    then(successFun,rejectFun){
        if(this.status === 'fulfilled'){
            successFun(this.value);
        }else{
            rejectFun(this.error);
        }
    }
}

let p1 = new MyPromise((resolve,reject) => {
    //成功的状态
    // resolve('成功的信息')
    reject("错误的信息")
}).then((res) => {
    //接受成功的信息
    console.log("成功",res)

},(error) => {
    //接受的是失败的信息
    console.log("错误",error)
})